<?php include('header.php'); ?>
<?php include('side.php'); ?>
<div class="layui-body">
	<div style="text-align:center; padding: 50px 30px;">
		<div class="layui-input-inline">
			<input type="text" name="token" lay-verify="token" size="18" autocomplete="off" class="layui-input" maxlength="16" style="text-align:center;background: #F8F8F8; font-size: 60px; padding: 80px 20px; color: #0C0; ">
		</div>
	</div>
	<fieldset class="layui-elem-field layui-field-title" style="margin: 20px 0;">
		<legend><?= Lang::app(['signin', 'list']) ?><span style="color: #BBA;font-size: 14px"></legend>
	</fieldset>
	<div class="layui-container">
		<div id="user-list" class="layui-row layui-col-space10">
			
		</div>
	</div>
</div>

<script>
var othis = $('input[name="token"]');
othis.focus();
//getSigninUser();

layui.use('layer', function() {
	
	var layer = layui.layer;
	
	othis.bind('blur', function() {
		
		
	}).bind('focus', function() {
		othis.val('');
	}).bind('keyup', function(event) {
		var code = event.keyCode || event.which || event.charCode;
		if (code == 13) {
			var len = othis.val().length;
			if (len == 16) {
				windos.ajaxPost('/site/sign_in', {token: othis.val()}, function(res) {
					if (res.code == 2) {
						layer.msg('该邀请码已签到，请核实身份');
					} else if (res.code == 3) {
						layer.msg('无效的邀请码，请核实身份');
					} else if (res.code == 1) {
						var card = assignUserTpl(res.data)
						$('#user-list').prepend(card);
						
					} else {
						layer.msg('程序错误');
					}
					
					//console.log(res);
				});
			} else {
				layer.msg('输入16位数邀请码');
			}
				
			othis.val('').focus();
		}
	});
	

});
	
function getSigninUser()
{
	windos.ajaxPost('/site/signin_users', {}, function(res) {
		if (res.code == 1) {
			var users = '';
			for (var i in res.data) {
				var item = res.data[i];
				var user = assignUserTpl(item);
				users += user;
			}
			$('#user-list').html(users);
		}
	});
}

function assignUserTpl(data)
{
	var tpl = '<div class="layui-card layui-col-md3" style="box-shadow: 0 0 5px rgba(0,0,0,.2)">\
		<div class="layui-card-header"' + (data.type == 2 ? ' style="color:#F60";font-weight:bold' : '') + ' title="' + data.name + '">欢迎 - ' + data.s_name + '</div>\
		<div class="layui-card-body">\
			<div class="layui-word-aux"><label class="layui-form-label">餐桌：</label><div class="layui-form-mid" style="color:#F60;font-weight:bold">' + data.table_name + '桌</div></div>\
			<div class="layui-word-aux"><label class="layui-form-label">邀请码：</label><div class="layui-form-mid">' + data.token + '</div></div>\
			<div class="layui-word-aux"><label class="layui-form-label">签到时间：</label><div class="layui-form-mid">' + windos.formatDate(data.confirm_time, 2) + '</div></div>\
		</div>\
	</div>';
	
	return tpl;
}
	
</script>

<?php include('footer.php'); ?>

